/**
 * 
 */
package us.gaaoc.framework.model.util;

import java.util.Collections;
import java.util.Comparator;
import java.util.List;

import us.gaaoc.framework.businessmodel.Filing;

/**
 * @author Sukahda Tapshalkar
 * Aug 15, 2007
 *
 */
/**
 * Inner Class to Sort the Filings by column="eventDateTime"
 * @author Sukahda Tapshalkar
 * July 30, 2007
 *
 */

public class FilingSorter extends SortableDataModel {
	
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	@SuppressWarnings("unchecked")
	public FilingSorter (String defaultColumnName, List<Filing>filingList) {
		super(defaultColumnName,filingList);
	}
	
	@SuppressWarnings({ "unchecked", "unchecked" })
	/**
	 * This method sorts the list depending on the previous order of the 
	 * list. If the list is not ordered then order in the ascending order.
	 */
	public void sort(final String column, final boolean ascending,final List filings) {
	
	 Comparator comparator = new Comparator()
        {
            public int compare(Object o1, Object o2)
            {
                Filing f1 = (Filing)o1;
                Filing f2 = (Filing)o2;
                if (column == null)
                {
                    return 0;
                }
                if (column.equals("eventDateTime"))
                {
                    return ascending ? f1.getEventDateTime().compareTo(f2.getEventDateTime()) : f2.getEventDateTime().compareTo(f1.getEventDateTime());
                }
                else if (column.equals("instantiationDateTime"))
                {
                    return ascending ? f1.getInstantiationDateTime().compareTo(f2.getInstantiationDateTime()) : f2.getInstantiationDateTime().compareTo(f1.getInstantiationDateTime());
                }
                
                else return 0;
            }
        };
        Collections.sort(filings, comparator);     
        	       
    }
	
}